//
//  MyAppDelegate.m
//  UnityFramework
//
//  Created by pub on 2024/2/22.
//

#import "MyAppDelegate.h"
#import "SDKController.h"
#import <CocoaLumberjack/CocoaLumberjack.h>
#import "UnityViewControllerListener.h"
#import "LifeCycleListener.h"
#import "LXBADInfo.h"
#import "ResVisitor.h"
#import "LXBConfig.h"
#import <ThinkingSDK/ThinkingSDK.h>
#import <StoreKit/StoreKit.h>
#import <MJExtension/MJExtension.h>
extern "C"{
    //void OCCall();
    void iOSChannelLogin();
    void iOSTrackEvent(const char *name,const char *eventArg);
    void iOSPayItem(const char *arg);
    void iOSCallChannelVoidFunWithArg(const char *name,const char *arg);
    void iOSSetUserData(const char *arg);
    void iOSTanWanEvent(const char *name,const char *arg);
}

//void OCCall(){
//    [[SDKController getInstance] openTestView];
//}

void iOSChannelLogin(){
    [[MyAppDelegate getInstance] iOSChannelLogin];
}
void iOSTrackEvent(const char *name,const char *eventArg){
    NSString *nsName = [NSString stringWithUTF8String:name];
    NSString *nsEventArg = [NSString stringWithUTF8String:eventArg];
    [[MyAppDelegate getInstance] iOSTrackEvent:nsName arg:nsEventArg];
}
void iOSPayItem(const char *arg){
    NSString *nsArg = [NSString stringWithUTF8String:arg];
    [[MyAppDelegate getInstance] iOSPayItem:nsArg];
}

void iOSCallChannelVoidFunWithArg(const char *name,const char *arg){
    NSString *nsName = [NSString stringWithUTF8String:name];
    NSString *nsArg = [NSString stringWithUTF8String:arg];
    [[MyAppDelegate getInstance] iOSCallChannelVoidFunWithArg:nsName arg:nsArg];
}
void iOSSetUserData(const char *arg){
    NSString *nsArg = [NSString stringWithUTF8String:arg];
    [[MyAppDelegate getInstance] iOSSetUserData:nsArg];
}
void iOSTanWanEvent(const char *name,const char *arg){
    NSString *nsName = [NSString stringWithUTF8String:name];
    NSString *nsArg = [NSString stringWithUTF8String:arg];
    [[MyAppDelegate getInstance ] iOSTanWanEvent:nsName arg:nsArg];
    
}

@interface  MyAppDelegate()<UnityViewControllerListener, LifeCycleListener, SKProductsRequestDelegate>{
    NSString *useId;
    
    NSString *mroleCreateTime;
    NSString *mroleLv;
    NSString *mmoneyNum;
    NSString *mstrRoleID;
    NSString *mroleName;
    BOOL geiAward;
    long mStartGame;
    ResVisitor *mUserInfo;
}

@end


static DDLogLevel ddLogLevel = DDLogLevelDebug;
static MyAppDelegate* app;

@implementation MyAppDelegate

+ (MyAppDelegate *)getInstance{
    return app;
}

#pragma mark - 生命周期

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary<UIApplicationLaunchOptionsKey,id> *)launchOptions{
    [super application:application didFinishLaunchingWithOptions:launchOptions];
    app = self;
    
    NSDictionary *dic = @{
        @"U8_GAME_ID": U8_GAME_ID,
        @"U8_PACKAGE_ID": U8_PACKAGE_ID,
        @"U8_CHANNEL": U8_CHANNEL,
        @"U8_PRIVATE_KEY":U8_PRIVATE_KEY,
        @"kApiPrefix":kApiPrefix,
        @"googleAdUnitId":googleAdUnitId,
        @"adJustAppToken":adJustAppToken,
        //1 是测试环境 其他真是环境
        @"adJustEnvironment":adJustEnvironment,
        //  //d973b221c3104f1c917a796b013dd090
        @"shushuAppid":shushuAppid,
        //shushu.boomgames.top:5000
        @"shushuUrl":shushuUrl,
        //1 是测试环境 其他真是环境
        @"shushuEnvironment":shushuEnvironment,
    };
    
    UnityRegisterViewControllerListener(self);
    
    [self addNotification];
    
    [[SDKController getInstance] sdkArgInit:dic];
    
    [[SDKController getInstance] application:application didFinishLaunchingWithOptions:launchOptions];
    
    
    return true;
}

- (void)addNotification{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(rewardedAdFinish:) name:AdRewardedNotiName object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(paySuccHandler:) name:PaySuccNotiName object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(payFailHandler:) name:PayFailNotiName object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(logoutHandler:) name:LogoutNotiName object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginSuccHandler:) name:LoginSuccNotiName object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginFailHandler:) name:LoginFailNotiName object:nil];
}

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options{
    BOOL handled = [[SDKController getInstance] application:app openURL:url options:options];
    if(handled){
        return YES;
    }
    return NO;
}


- (void)viewDidAppear:(NSNotification*)notification{
    
    [DDLog addLogger:[DDOSLogger sharedInstance]];
    DDFileLogger *fileLog = [[DDFileLogger alloc] init];
    fileLog.rollingFrequency = 60 * 60 *24;
    fileLog.logFileManager.maximumNumberOfLogFiles = 3;
    [DDLog addLogger:fileLog];
    
    UIViewController *ctl = [[UnityFramework getInstance] appController].rootViewController;
    
    [[SDKController getInstance] AdInitAfterControllerDidInit:ctl];
   
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

#pragma mark - 回调通知
- (void)onInitSuccess{
    [self SendMsgToUnity:@"ReceiverSDKInit" message:@""];
    
    NSDictionary *userType = @{
        @"userType":@"TanWan",
    };
    NSString *uStr = [self jsonStringWithDict:userType];
    [self iOSSetUserData:uStr];
    NSDictionary *userType1 = @{
        @"user_type1":@"TanWan",
    };
    NSString *uStr2 = [self jsonStringWithDict:userType1];
    [self iOSSetUserData:uStr2];
}


- (void)rewardedAdFinish:(NSNotification *)noti{
    LXBADInfo *info = (LXBADInfo *)noti.object;
    NSLog(@"---%@", [info mj_JSONString]);
    if(info != nil && info.reward == YES){
        [self AdHandler:@"onRewardedVideoAdRewarded" withArg:@""];
        [self AdHandler:@"onRewardedVideoAdClosed" withArg:@""];
        NSDictionary *finishAd = @{
            @"ad_type":@"激励视屏",
            @"adunit_id":info.adID,
            @"earnings":info.amount,
            @"currency_type":@"USD",
            @"ad_platform":@"admob",
        };
        NSString * args = [self jsonStringWithDict:finishAd];
        NSLog(@"finishAd%@",args);
        [self SendCommonReceive:@"OverSeaEcpm" mArg:args];
    }
}

- (void)paySuccHandler:(NSNotification *)noti{
    NSLog(@"pay succ  %@", noti.object);
    NSDictionary * dic = [self dictionaryWithJsonString:noti.object];
    int price = [[dic objectForKey:@"amount"] intValue];
    int price2 = price / 100;
    [[SDKController getInstance] trackPurchase:AdjustPurchase amount:price2 currency:@"USD"];
    
    
    NSLog(@"Demo:购买成功");
    NSDictionary *paysucc = @{
        @"code": @2,
        @"info": @"succ",
    };
    NSString *payStr = [self jsonStringWithDict:paysucc];
    [self SendMsgToUnity:@"PayResult" message:payStr];
}

- (void)payFailHandler:(NSNotification *)noti{
    NSLog(@"pay fail  %@", noti.object);
    NSString *reason = noti.object;
    
    if(reason == nil){
        reason = @"unkown";
    };
    NSDictionary *paysucc = @{
        @"code": @1,
        @"info": reason,
    };
    NSString *payStr = [self jsonStringWithDict:paysucc];
    [self SendMsgToUnity:@"PayResult" message:payStr];
}

- (void)logoutHandler:(NSNotification *)noti{
    mUserInfo = nil;
    [self SendMsgToUnity:@"ChannelLogout" message:@"xxxx"];
    [TDAnalytics logout];
}


- (void)loginFailHandler:(NSNotification *)noti{
    NSLog(@"loginFailed");
    NSString *re = noti.object;
    if(re == nil){
        re = @"unkown";
    }
    [self SendMsgToUnity:@"SDKLoginFail" message:@""];
    NSDictionary *dic = @{
        @"result":@"失败",
        @"fail_reason":re,
    };
    NSString *json = [self jsonStringWithDict:dic];
    [self iOSTrackEvent:@"login_result" arg:json];
}

- (void)loginSuccHandler:(NSNotification *)noti{
    ResVisitor *sdkUser = noti.object;
    NSLog(@"loginSuccess");
    //研发服务端使用sessionId去SDK服务端进行登录验证
    NSString *uid = [NSString stringWithFormat:@"%li", sdkUser.account_id] ;
    NSLog(@"Demo:登录成功 uid:%@ ",uid);
    [self userLogin:sdkUser];
    [[SDKController getInstance] showToast:@"login succ"];
    
    [self setBoomid];
}

- (void)setBoomid{
    
    NSString *uid = [NSString stringWithFormat:@"%li", mUserInfo.account_id];
    [TDAnalytics setSuperProperties:@{
       @"boom_id":uid,
    }];
    [TDAnalytics userSet:@{
        @"boom_id":uid
    }];
}


- (void)userLogin:(ResVisitor *)sdkUser{
    if (mUserInfo != nil) {
        return;
    }
    mUserInfo = sdkUser;
    NSString *idStr = [NSString stringWithFormat:@"%li", sdkUser.account_id];
    [self SendMsgToUnity:@"ReceiverChannelLoginCallBack" message:idStr];
    [self SendMsgToUnity:@"HasVerified" message:@"1"];

    NSDictionary *eventProperties = @{
        @"result": @"成功",
        @"login_id": idStr,
        @"login_type": @"Tanwan"
    };
    [TDAnalytics track:@"login_result" properties:eventProperties];
    
    NSDictionary *myUserInfo = @{
        @"UserID": idStr,
        @"UserName": @"noName",
    };
    useId = idStr;
    
    NSString *infoStr = [self jsonStringWithDict: myUserInfo];
    [self SendMsgToUnity:@"ReceiverUserInfo" message:infoStr];
    
    NSDate *datenow = [NSDate date];
    mStartGame = (long)[datenow timeIntervalSince1970];
    
    NSDictionary *verified = @{
        @"verified_status": @(YES),
    };
    
    [self iOSSetUserDataWithDic:verified];
    
    
    NSDictionary *other_account = @{
        @"other_account": idStr,
    };
    NSString *other_accountstr = [self jsonStringWithDict: other_account];
    [self iOSSetUserData:other_accountstr];
    
    [self SendCommonReceive:@"isOverseas" mArg:@""];
}

#pragma mark - 回调结束
-(void)SendCommonReceive:(NSString *)name mArg:(NSString *)arg{
    NSDictionary *dic = @{
        @"FunName":name,
        @"Arg":arg
    };
    
    NSString *js = [self jsonStringWithDict:dic];
    [self SendMsgToUnity:@"CommonReceive" message:js];
}


#pragma mark - C# function

- (void)iOSChannelLogin{
    dispatch_async(dispatch_get_main_queue(), ^(){
        [self iOSTrackEvent:@"login_call" arg:@""];
        [self SendPrePropertie];
        //NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"];
        //NSMutableDictionary *infoDict = [NSMutableDictionary dictionaryWithContentsOfFile:bundlePath];
        //NSString *sdkName = [infoDict objectForKey:@"sdkName"];
        NSString *sdkName = @"europe_america";
        [self SendMsgToUnity:@"ReceiveSDKFlag" message:sdkName];
        NSLog(@"sdkName%@",sdkName);
        [[SDKController getInstance] sdkLogin];
    });
}


- (void)iOSTrackEvent:(NSString *)name arg:(NSString *)arg{
    if ([arg isEqual:@""]) {
        [TDAnalytics track:name properties:@{}];
    }
    else{
        NSDictionary *dic = [self dictionaryWithJsonString:arg];
        [TDAnalytics track:name properties:dic];
    }
}


- (void)iOSPayItem:(NSString *)arg{
    dispatch_async(dispatch_get_main_queue(), ^(){

        NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"];
        NSMutableDictionary *infoDict = [NSMutableDictionary dictionaryWithContentsOfFile:bundlePath];
        NSString *appId = [infoDict objectForKey:@"GameAppID"];

        NSDictionary *payDic = [self dictionaryWithJsonString:arg];
        NSMutableDictionary *payInfoDict = [NSMutableDictionary dictionary];
        //NSString *extstr = [NSString stringWithFormat:@"Te%@",@"stServer"];
        NSNumber *uin = payDic[@"uin"];
        NSString *roleId = [NSString stringWithFormat:@"%@",uin];
        NSString *nsRig = payDic[@"rig"];
//        req.product_id = dic[@"product_id"];
//        NSString *amount = dic[@"amount"];
//        req.amount = [amount intValue];
//        req.body = dic[@"body"];
//        req.detail = dic[@"detail"];
//        //游戏服id
//        NSString *serverId = dic[@"server_id"];
//        req.server_id = [serverId intValue];
//        //必须传
//        req.notify_url = dic[@"notify_url"];
//        //必须传
//        req.extension = dic[@"extension"];
        NSDictionary *dic = @{
            @"product_id":payDic[@"abordId"],//内购商品ID
            @"amount":payDic[@"dollar"],// 价格
            @"body":payDic[@"payName"],// 名字
            @"detail":payDic[@"payName"],
            @"server_id":@"1",
            @"notify_url":payDic[@"notify_url"],
            @"extension":[NSString stringWithFormat:@"%@,%@,%@",payDic[@"id"],U8_PACKAGE_ID,nsRig],
        };
        
        NSLog(@"payarg %@" , [self jsonStringWithDict:dic]);
        
        [[SDKController getInstance] lxbPay:dic];
    });
}

- (void)iOSCallChannelVoidFunWithArg:(NSString *)name arg:(NSString *)arg{
    if ([name isEqual:@"setSuperProperties"]) {
        if ([arg isEqual:@""]) {
            
        }
        else{
            NSDictionary *dic = [self dictionaryWithJsonString:arg];
            [TDAnalytics setSuperProperties:dic];
        }
    }
    else if([name isEqual:@"showRewardedVideo"]){
        dispatch_async(dispatch_get_main_queue(), ^(){
            /*
            if ([arg isEqual:@"true"]) {
                [self AdHandler:@"onRewardedVideoAdRewarded" withArg:@""];
                [self AdHandler:@"onRewardedVideoAdClosed" withArg:@""];
            }
            else{
                RewardedAdPutgo();
            }
            */
            [[SDKController getInstance] showRewardedAd];
            
        });
    }
    
    else if ([name isEqual:@"survey"]){
        
    }
    
    else if([name isEqual:@"isSurvey"]){
       
    }
    
    else if([name isEqual:@"logout"]){
        dispatch_async(dispatch_get_main_queue(), ^(){
            [[SDKController getInstance] sdkLogout];;
        });
    }
    
    else if([name isEqual:@"ShuShuTimeEventWithName"]){
        [TDAnalytics timeEvent:arg];
    }
    
    else if([name isEqual:@"appReview"]){
        dispatch_async(dispatch_get_main_queue(), ^(){
                if (@available(iOS 14.0,*)) {
                    
                }
                else if(@available(iOS 10.3,*)){
                    [SKStoreReviewController requestReview];
                }
            });
    }
    else if ([name isEqual:@"switchAccount"]){
        dispatch_async(dispatch_get_main_queue(), ^(){
            [[SDKController getInstance] sdkLogout];
        });
    }
    else if ([name isEqual:@"launchAccountPage"]){
        dispatch_async(dispatch_get_main_queue(), ^(){
            [[SDKController getInstance] openCenterView];
        });
    }
    else if ([name isEqual:@"userEventTrack"]){
        //游戏事件
        NSLog(@"-------------userEventTrack   %@",arg);
    }
    
    else if ([name isEqual:@"actionEventTrack"]){
        //flyer
        NSDictionary *nameAndArg = [self dictionaryWithJsonString:arg];
        NSDictionary *eArg = [self dictionaryWithJsonString:nameAndArg[@"eventParam"]];
        NSString *eName = [nameAndArg objectForKey:@"eventName"];
        
        //NSLog(@"firebase %@", eName);
        if([eName isEqual: @"login_day2"]){
            //[[SDKController getInstance] adjustTrackEventWithToken:AdjustLogin2];
        }
    }
    
    else if ([name isEqual:@"lauchGoogleReview"]){
        dispatch_async(dispatch_get_main_queue(), ^(){
                if (@available(iOS 14.0,*)) {
                    
                }
                else if(@available(iOS 10.3,*)){
                    [SKStoreReviewController requestReview];
                }
            });
    }
    
    else if([name isEqual:@"queryProductDetailsAsync"]){
        [self requestProductData:arg];
        NSLog(@"queryProdu%@",arg);
    }
    else if([name isEqual:@"SDKInit"]){
        [self SendMsgToUnity:@"ReceiverSDKInit" message:@""];
    }
    
    //NSLog(@"---%@", name);
}

#pragma mark - C#function end

-(void) SendPrePropertie{
    TDPresetProperties *presetProperties = [TDAnalytics getPresetProperties];
    NSDictionary *properties = [presetProperties toEventPresetProperties];
    NSString *proJson = [self jsonStringWithDict:properties];
    [self SendMsgToUnity:@"ReceiverPresetProperties" message:proJson];
}

-(void) SendMsgToUnity:(NSString *)funcName message:(NSString *)msg
{
    dispatch_async(dispatch_get_main_queue(), ^(){
        UnityFramework *frame = [UnityFramework getInstance];
        const char *funName = [funcName UTF8String];
        const char *toUnity = [msg UTF8String];
        [frame sendMessageToGOWithName:"Global" functionName:funName message:toUnity];
        });
}


- (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString{
    if (jsonString == nil) {
        return nil;
    }
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
                                                        options:NSJSONReadingMutableContainers
                                                          error:&err];
    if(err)
    {
        return nil;
    }
    return dic;
}
- (NSString *)jsonStringWithDict:(NSDictionary *)dict {
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
    NSString *jsonString;
    if (!jsonData) {
    }else{
        jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
    }
    return jsonString;
}



- (void)requestProductData:(NSString *)type{
    NSArray *array = [type componentsSeparatedByString:@","];
    //NSArray *array = [NSArray arrayWithObjects:@"test.wanz.game_30",@"test.wanz.game_128",@"test.wanz.game_328",@"test.wanz.game_648",@"test.wanz.game_6", nil];
    NSSet *nsset = [NSSet setWithArray:array];
    SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:nsset];
    request.delegate = self;
    [request start];
}


#pragma -make 查询回调
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
    NSArray *product = response.products;
    if(product.count==0){
        NSLog(@"no productID");
        return;
    }
    NSMutableArray *arr = [NSMutableArray arrayWithCapacity:16];
    for(SKProduct *pro in product) {
        NSString *formattedPrice = [NSString stringWithFormat:@"%@%@%@",[[pro priceLocale] currencyCode],[[pro priceLocale] currencySymbol],[pro price]];
        NSDictionary *dic = @{
            @"productId":[pro productIdentifier],
            @"productName":[pro localizedTitle],
            @"productDes":[pro localizedDescription],
            @"currency":[[pro priceLocale] currencyCode],
            @"formattedPrice":formattedPrice,
            @"price":[pro price],
        };
        [arr addObject:dic];
    }
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:arr
                                                       options:NSJSONWritingPrettyPrinted
                                                         error:&error];
    if (error) {
        NSLog(@"Got an error: %@", error);
    } else {
        
        NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
        
        NSString *temp = [jsonString stringByReplacingOccurrencesOfString:@" " withString:@""];
        temp = [temp stringByReplacingOccurrencesOfString:@"\r" withString:@""];
        temp = [temp stringByReplacingOccurrencesOfString:@"\n" withString:@""];
        NSLog(@"jsonString  %@",temp);
        [self SendCommonReceive:@"ReceiverProductDetails" mArg:temp];
    }
}

#pragma -mark 数数

- (void)iOSSetUserData:(NSString *)arg{
    NSDictionary *dic = [self dictionaryWithJsonString:arg];
    if (dic != nil) {
        [TDAnalytics userSet:dic];
    }
}

-(void)iOSSetUserDataWithDic:(NSDictionary *)arg{
    if (arg != nil) {
        [TDAnalytics userSet:arg];
    }
}

- (void)iOSTanWanEvent:(NSString*)name arg:(NSString *)arg{
    NSDictionary *dicArg = [self dictionaryWithJsonString:arg];
    //{"RoleLv":13,"RoleId":101101,"MoneyNum":16113,"RoleCreateTime":0,"Balance":16113,"roleName":"卡面来打"}
    NSString *roleLv = dicArg[@"RoleLv"];
    NSString *moneyNum = dicArg[@"MoneyNum"];
    NSString *strRoleID = dicArg[@"RoleId"];
    NSString *roleName = dicArg[@"roleName"];
    mroleLv = roleLv;
    mmoneyNum = moneyNum;
    mstrRoleID = strRoleID;
    mroleName = roleName;
//    NSDictionary *roleInfoDict = @{ GameRoleName   : roleName, // 角色名
//                                    GameSerID   : @"0", //服务器ID，纯数字字符串
//                                    GameSerName : @"0",//服务器名
//                                    GameRoleLevel  : roleLv, //角色等级
//                                    GameRoleID     : strRoleID,  //角色ID
//                                    GameSurplusNum : moneyNum  //剩余元宝/钻石 数量
//                                    };
    NSInteger mType = [name integerValue];
    if(mType == 1){
        //    private const string SelectServerType = "1";
        
    }
    else if (mType == 2){
        //    private const string CreateRoleType = "2";
        [[SDKController getInstance] firebaseCreateAccount];
        [[SDKController getInstance] firebaseCreateRole];
        
        [[SDKController getInstance] adjustTrackEventWithToken: AdjustRegist];
        [[SDKController getInstance] adjustTrackEventWithToken: AdjustCreateRole];
    }
    else if (mType == 3){
        //    private const string EnterGameType = "3";
        [[SDKController getInstance] firebaseEnterGame];
        //NSLog(@"%@mstrRoleID",mstrRoleID);
        //
        NSString *strId = [NSString stringWithFormat:@"%@", strRoleID];
        [TDAnalytics login:strId];
        [[SDKController getInstance] adjustAddTaAccountId:strId];
        
        [self setBoomid];
    }
    else if (mType == 4){
        //    private const string LevelUpType = "4";
        [[SDKController getInstance] firebaseLevelUp:roleLv];
    }
    else if (mType == 5){
        //    private const string TutorialCompletion = "6";
    }

//#define AdjustRegist @"lltxzj"
//#define AdjustCreateRole @"tdnus7"
//#define AdjustLogin2 @"c8pq5i"
}


- (void)AdHandler:(NSString *)funcName withArg:(NSString *)arg{
    NSDictionary *dic = @{
        @"FunName":funcName,
        @"Arg":arg
    };
    NSString *json = [self jsonStringWithDict:dic];
    [self SendMsgToUnity:@"AdHandler" message:json];
}


@end

IMPL_APP_CONTROLLER_SUBCLASS(MyAppDelegate)
